home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / JAVA_UTL / C2JAVA / PARSER.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-07  |  5.0 KB  |  166 lines

  1. /*
  2. ##############################################################################
  3. #
  4. #  c2j          96/04/04   Chris Laffra
  5. #
  6. #  Copyright (c) 1995-1996 Morgan Stanley & Co., Inc. All Rights Reserved.
  7. #
  8. #  Permission to use, copy, modify, and distribute this software
  9. #  and its documentation for NON-COMMERCIAL purposes and without
  10. #  fee is hereby granted provided that this copyright notice
  11. #  appears in all copies. Please contact email: laffra@ms.com
  12. #  for further copyright and licensing information.
  13. #
  14. #  MORGAN STANLEY MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
  15. #  OF THIS SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  16. #  TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. #  PARTICULAR PURPOSE, OR NON-INFRINGEMENT. MORGAN STANLEY SHALL NOT BE LIABLE
  18. #  FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  19. #  DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  20. #
  21. ##############################################################################
  22. */
  23.  
  24. ////////////////////////////////   See README file  //////////////////////////
  25.  
  26. class SomethingWithAName {
  27. public:
  28.   SomethingWithAName(const char *name_) {
  29.     _name = new char[strlen(name_)+1]; 
  30.     strcpy(_name, name_);
  31.   }
  32.   ~SomethingWithAName() {
  33.     delete _name;
  34.   }
  35.   void name(const char *name_) {
  36.     delete _name;
  37.     _name = new char[strlen(name_)+1]; 
  38.     strcpy(_name, name_);
  39.   }
  40.   const char *name(void) const { return _name; }
  41.     
  42. protected:
  43.   char *_name;
  44. };
  45.  
  46. class SomethingWithAType {
  47. public:
  48.   SomethingWithAType(const char *type_) {
  49.     _type = new char[strlen(type_)+1]; 
  50.     strcpy(_type, type_);
  51.   }
  52.   ~SomethingWithAType() {
  53.     delete _type;
  54.   }
  55.   void type(const char *type_) {
  56.     delete _type;
  57.     _type = new char[strlen(type_)+1]; 
  58.     strcpy(_type, type_);
  59.   }
  60.   const char *type(void) const { return _type; }
  61.     
  62. protected:
  63.   char *_type;
  64. };
  65.  
  66. class ParmList : public SomethingWithAName, public SomethingWithAType 
  67. {
  68. public:
  69.   ParmList(const char *type_, const char *name_, ParmList *next_) :
  70.         SomethingWithAName(name_), SomethingWithAType(type_), _next(next_) { }
  71.   ~ParmList() { }
  72.   ParmList *next(void) { return _next; }
  73.   int length() { return (_next) ? _next->length() + 1 : 1; }
  74.   void Delete();
  75.   void printNames(FILE*);
  76.   void printAsParms(FILE*);
  77.   void printTypes(FILE*);
  78.   void printTypes(char *buf);
  79. private:
  80.   ParmList *_next;
  81. };
  82.  
  83. class ClassRepresentation;
  84.  
  85.  
  86. class ClassMemberRepresentation : public SomethingWithAName, 
  87.                   public SomethingWithAType 
  88. {
  89. public:
  90.   enum Type { Variable, Enum, Array, Method, InlinedMethod, 
  91.                     Constructor, InlinedConstructor, 
  92.                     Destructor, InlinedDestructor, 
  93.                 StaticMethod, StaticInlinedMethod };
  94.   ClassMemberRepresentation(const char *type_, const char *name_,
  95.             Type member_type_, ClassMemberRepresentation *next_,
  96.             ParmList *parameters_,
  97.             const char *accessor_) :
  98.         SomethingWithAName(name_), SomethingWithAType(type_), 
  99.     _type(member_type_), _next(next_), 
  100.     _parameters(parameters_), _accessor(accessor_) { }
  101.   ~ClassMemberRepresentation() { }
  102.   ClassMemberRepresentation *next(void) { return _next; }
  103.   int length() { return (_next) ? _next->length() + 1 : 1; }
  104.   void member_type(Type t_) { _type = t_; };
  105.   Type member_type() { return _type; };
  106.   void print(ClassRepresentation *c);
  107.   void accessor(const char *accessor_) { _accessor = accessor_; };
  108.   const char *accessor() { return _accessor; };
  109.  
  110. protected:
  111.   ClassMemberRepresentation *_next;
  112.   Type _type;
  113.   ParmList *_parameters;
  114.   const char *_accessor;
  115. };
  116.  
  117.  
  118. class SuperClassRepresentation : public SomethingWithAName {
  119. public:
  120.   SuperClassRepresentation(const char *name_, SuperClassRepresentation *next_) 
  121.       : SomethingWithAName(name_), _next(next_) { }
  122.   SuperClassRepresentation *next() { return _next; };
  123. protected:
  124.   SuperClassRepresentation* _next;
  125. };
  126.  
  127.  
  128. class ClassRepresentation : public SomethingWithAName 
  129. {
  130. public:
  131.   ClassRepresentation(const char *name_, ClassRepresentation *next_,
  132.                             int is_super_class) :
  133.     SomethingWithAName(name_), _next(next_), 
  134.             _n_members(0), _super(0), 
  135.             _nested(0), 
  136.             _is_super(is_super_class) { }
  137.   ~ClassRepresentation() { }
  138.   int numberOfMembers(void) { return _n_members; }
  139.   ClassMemberRepresentation *member(int n) {
  140.     ClassMemberRepresentation *m;
  141.     for (m = _members; m && n>0; n--) m = m->next();
  142.     return (m);
  143.   }
  144.   void members(ClassMemberRepresentation *members_) {
  145.     _members = members_;
  146.     _n_members = _members ? _members->length() : 0;
  147.   }
  148.   void addSuperClass(ClassRepresentation *super_) {
  149.     _super = new SuperClassRepresentation(super_->name(), _super);
  150.   }
  151.   ClassMemberRepresentation *members(void) { return _members; }
  152.   ClassRepresentation *next(void) { return _next; }
  153.   SuperClassRepresentation *super() { return _super; };
  154.   void print();
  155.   int nested(void) { return _nested; }
  156.   void nested(int nested_) { _nested = nested_; }
  157.     
  158. protected:
  159.   ClassMemberRepresentation *_members;
  160.   int _n_members;
  161.   int _is_super;
  162.   int _nested;
  163.   ClassRepresentation *_next;
  164.   SuperClassRepresentation *_super;
  165. };
  166.